# GDIR define
GDIR=../../..

# MACIPATH define
MACIPATH=$(GDIR)/MaCI


# External includes
include $(GDIR)/GIMI/Makefile.gimi
include $(MACIPATH)/interfaces/MaCI-interfaces.Makefile


# params
CC=gcc
CXX=g++
EXTRADEFS=-DLINUX_OS
MACIPATH=$(GDIR)/MaCI
UTILSPATH=$(GDIR)/utils
BUSPATH=$(MACIPATH)/bus
DRIVERPATH=$(MACIPATH)/drivers
MACIINTERFACEPATH=$(MACIPATH)/interfaces
INCLUDES=-I$(UTILSPATH) $(INCGIMI) \
	$(MACI_INCLUDE_PATHS)
CFLAGS=-O0 -g3 -Wall $(INCLUDES) $(CE) \
	$(EXTRADEFS)
CPPFLAGS=-O0 -g3 -Wall $(INCLUDES) -Weffc++ $(EXTRADEFS)
LD=g++
LDFLAGS=-ljpeg
LIBS=-lrt -lpthread $(LIBSGIMI) `libpng-config --libs`


# Sources 'base' (required external links)
SRCSC=$(CGIMI) 
SRCSCPP=$(CPPGIMI) $(MACI_EXT_SRC_CPP) $(MACI_BASE_SRC_CPP)
VPATH=

# Construct final lists of CPP and C objects
OBJSC=$(SRCSC:.c=.o)
OBJSCPP=$(SRCSCPP:.cpp=.opp)

# Define COMPILE and LINK commands
COMPILEC=$(CC) $(CFLAGS) -c
COMPILECPP=$(CXX) $(CPPFLAGS) -c
LINK=$(LD) $(LDFLAGS)

.PHONY: all clean real-clean


all: ImageClient ImageServer ImageData_standalone

ImageServer: ImageData.opp ImageContainer.opp ImageServer.opp \
	     $(GDIR)/ImageUtils/JPEGEncoder/JPEGEncoder.opp \
	     $(GDIR)/ImageUtils/JPEGDecoder/JPEGDecoder.opp \
	     $(GDIR)/ImageUtils/PNGDecoder/PNGDecoder.opp \
	     $(GDIR)/ImageUtils/PNGEncoder/PNGEncoder.opp \
	     $(GDIR)/ImageUtils/conversions/YUYV_to_RGB.o 
	@echo "ImageServer components - Compiled OK."

ImageClient: ImageData.opp ImageContainer.opp ImageClient.opp \
	     $(GDIR)/ImageUtils/JPEGEncoder/JPEGEncoder.opp \
	     $(GDIR)/ImageUtils/JPEGDecoder/JPEGDecoder.opp \
	     $(GDIR)/ImageUtils/PNGDecoder/PNGDecoder.opp \
	     $(GDIR)/ImageUtils/PNGEncoder/PNGEncoder.opp \
	     $(GDIR)/ImageUtils/conversions/YUYV_to_RGB.o 
	@echo "ImageClient components - Compiled OK."


ImageData_standalone: $(OBJSC) $(OBJSCPP) ImageContainer.opp \
	     ImageConversion.opp ImageData.cpp \
	     $(GDIR)/ImageUtils/JPEGEncoder/JPEGEncoder.opp \
	     $(GDIR)/ImageUtils/JPEGDecoder/JPEGDecoder.opp \
	     $(GDIR)/ImageUtils/PNGDecoder/PNGDecoder.opp \
	     $(GDIR)/ImageUtils/PNGEncoder/PNGEncoder.opp \
	     $(GDIR)/ImageUtils/conversions/YUYV_to_RGB.o 
	rm -f ImageData.opp
	@$(COMPILECPP) -D COMPILE_IMAGEDATA_STANDALONE_MAIN \
	ImageData.cpp -o ImageData.opp
	@echo "      [CXX-STANDALONE] ImageData.cpp"
	@$(LINK) -o $@ $(OBJSC) $(OBJSCPP) ImageContainer.opp \
	ImageData.opp ImageConversion.opp \
	$(GDIR)/ImageUtils/JPEGEncoder/JPEGEncoder.opp \
	$(GDIR)/ImageUtils/JPEGDecoder/JPEGDecoder.opp \
	$(GDIR)/ImageUtils/PNGDecoder/PNGDecoder.opp \
	$(GDIR)/ImageUtils/PNGEncoder/PNGEncoder.opp \
  $(GDIR)/ImageUtils/conversions/YUYV_to_RGB.o \
	$(LIBS)


clean:
	@rm -f *.o *.opp *~ ImageData_standalone
	@echo "      [CLEAN]"

real-clean realclean: clean

# Compile rule for all .o (.c) file
%.o:	%.c
	@$(COMPILEC) -o $@ $<
	@echo "      [CC] $<"

# Compile rule for all .opp (.cpp) files
%.opp:	%.cpp
	@$(COMPILECPP) -o $@ $<
	@echo "      [CXX] $<"


